﻿using PlaceOrder_Shared.Models.Daily;
using PlaceOrder_Shared.Models.Trade;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PlaceOrder_Shared.Models.Common
{

    //public class UserTrade : BindableBase
    //{
    //    public enum UserTradeOrderTypeEnum
    //    {
    //        Bid,
    //        Ofr
    //    }

    //    public UserTrade() { }

    //    public UserTrade(UserTrade t)
    //    {
    //        Target = t.Target;
    //        ChatID = t.ChatID;
    //        Broker = t.Broker;
    //        ReceiverId = t.ReceiverId;
    //        TsCode = t.TsCode;
    //        UserTradeID = t.UserTradeID;
    //        Status = t.Status;
    //        Volume = t.Volume;
    //        Price = t.Price;
    //        DeliveryDate = t.DeliveryDate;
    //        DealType = t.DealType;
    //        DailyID = t.DailyID;
    //    }

    //    private Int64 id;
    //    public Int64 Id
    //    {
    //        get { return id; }
    //        set { id = value; RaisePropertyChanged(); }
    //    }

    //    private string target;
    //    public string Target
    //    {
    //        get { return target; }
    //        set { target = value; RaisePropertyChanged(); }
    //    }

    //    private string chatID;
    //    public string ChatID
    //    {
    //        get { return chatID; }
    //        set { chatID = value; RaisePropertyChanged(); }
    //    }

    //    private string broker;
    //    public string Broker
    //    {
    //        get { return broker; }
    //        set { broker = value; RaisePropertyChanged(); }
    //    }

    //    private int brokerID;
    //    public int BrokerID
    //    {
    //        get { return brokerID; }
    //        set { brokerID = value; RaisePropertyChanged(); }
    //    }

    //    private int receiverId;
    //    public int ReceiverId
    //    {
    //        get { return receiverId; }
    //        set { receiverId = value; RaisePropertyChanged(); }
    //    }

    //    private string tsCode;
    //    public string TsCode
    //    {
    //        get { return tsCode; }
    //        set { tsCode = value; RaisePropertyChanged(); }
    //    }

    //    private Int64 userTradeID;
    //    public Int64 UserTradeID
    //    {
    //        get { return userTradeID; }
    //        set { userTradeID = value; RaisePropertyChanged(); }
    //    }

    //    private int userID;
    //    public int UserID
    //    {
    //        get { return userID; }
    //        set { userID = value; RaisePropertyChanged(); }
    //    }

    //    private string userName;
    //    public string UserName
    //    {
    //        get { return userName; }
    //        set { userName = value; RaisePropertyChanged(); }
    //    }

    //    private int status;
    //    public int Status
    //    {
    //        get { return status; }
    //        set { status = value; RaisePropertyChanged(); }
    //    }

    //    private string statusText;
    //    public string StatusText
    //    {
    //        get { return statusText; }
    //        set { statusText = value; RaisePropertyChanged(); }
    //    }

    //    private int volume;
    //    public int Volume
    //    {
    //        get { return volume; }
    //        set { volume = value; RaisePropertyChanged(); }
    //    }

    //    private decimal price;
    //    public decimal Price
    //    {
    //        get { return price; }
    //        set { price = value; RaisePropertyChanged(); }
    //    }

    //    private DateOnly deliveryDate;
    //    public DateOnly DeliveryDate
    //    {
    //        get { return deliveryDate; }
    //        set { deliveryDate = value; RaisePropertyChanged(); }
    //    }

    //    private string dealType;
    //    public string DealType
    //    {
    //        get { return dealType; }
    //        set { dealType = value; RaisePropertyChanged(); }
    //    }

    //    private DateTime time;
    //    public DateTime Time
    //    {
    //        get { return time; }
    //        set { time = value; RaisePropertyChanged(); }
    //    }

    //    private string command;
    //    public string Command
    //    {
    //        get { return command; }
    //        set { command = value; RaisePropertyChanged(); }
    //    }

    //    private UserTradeOrderTypeEnum orderType;
    //    public UserTradeOrderTypeEnum OrderType
    //    {
    //        get { return orderType; }
    //        set { orderType = value; RaisePropertyChanged(); }
    //    }

    //    private Guid guid;
    //    public Guid Guid
    //    {
    //        get { return guid; }
    //        set { guid = value; RaisePropertyChanged(); }
    //    }

    //    private int dailyID;
    //    public int DailyID
    //    {
    //        get { return dailyID; }
    //        set { dailyID = value; RaisePropertyChanged(); }
    //    }

    //    private int onHoldVolume;
    //    public int OnHoldVolume
    //    {
    //        get { return onHoldVolume; }
    //        set { onHoldVolume = value; RaisePropertyChanged(); }
    //    }

    //    private string counterParty;
    //    public string CounterParty
    //    {
    //        get { return counterParty; }
    //        set { counterParty = value; RaisePropertyChanged(); }
    //    }

    //    public override string ToString()
    //    {
    //        return $"UserTrade [id={id}, 目标={Target}, ChatID={ChatID}, Broker={Broker}, BrokerID={BrokerID}, " +
    //               $"ReceiverId={ReceiverId}, 券码={TsCode}, UserTradeID={UserTradeID}, UserID={UserID}, UserName={UserName}, " +
    //               $"状态={StatusText}, Volume={Volume}, 价格={Price}, DeliveryDate={DeliveryDate}, " +
    //               $"交易类型={DealType}, Time={Time}, 命令={Command}, OrderType={OrderType}, Guid={Guid}, " +
    //               $" OnHoldVolume={OnHoldVolume}, CounterParty={CounterParty}]";
    //    }
    //}

    public class UserTrade:UINotifyPropertyChanged
    {
        private bool isChild;

        public bool IsChildren
        {
            get { return isChild; }
            set { isChild = value; OnPropertyChanged(); }
        }


        private bool isChildrenVisibility;

        public bool IsChildrenVisibility
        {
            get { return isChildrenVisibility; }
            set { isChildrenVisibility = value; OnPropertyChanged(); }
        }


        private bool _isVisibility;

        public bool IsVisibility
        {
            get { return _isVisibility; }
            set
            {
                if (_isVisibility != value)
                {
                    _isVisibility = value;
                    OnPropertyChanged(nameof(IsVisibility)); // Notify that IsVisibility property has changed
                }
            }
        }


        public enum UserTradeOrderTypeEnum
        {
            Bid,
            Ofr
        }
        public UserTrade()
        {

        }
        public UserTrade(UserTrade t)
        {
            Target = t.Target;
            ChatID = t.ChatID;
            Broker = t.Broker;
            ReceiverId = t.ReceiverId;
            TsCode = t.TsCode;
            UserTradeID = t.UserTradeID;
            Status = t.Status;
            Volume = t.Volume;
            Price = t.Price;
            DeliveryDate = t.DeliveryDate;
            DealType = t.DealType;
            DailyID = t.DailyID;
        }
        public Int64 Id { get; set; }
        public string Target { get; set; }
        public string ChatID { get; set; }
        public string Broker { get; set; }
        public int? BrokerID { get; set; }
        public int? ReceiverId { get; set; }
        public string TsCode { get; set; }
        public Int64 UserTradeID { get; set; }
        public int UserID { get; set; }
        public string UserName { get; set; }
        public int Status { get; set; }
        public string StatusText { get; set; }
        public int Volume { get; set; }
        public decimal Price { get; set; }//询价
        public decimal? RealPrice { get; set; }//成交价
        public DateOnly DeliveryDate { get; set; }
        public string DealType { get; set; }
        public DateTime Time { get; set; }
        public string Command { get; set; }
        public UserTradeOrderTypeEnum OrderType { get; set; }
        public Guid Guid { get; set; }
        public int DailyID { get; set; }
        public int OnHoldVolume { get; set; }

        /// <summary>
        /// 交易对手（24/7/10） 待lihao处理发送给我
        /// </summary>
        public string CounterParty { get; set; }

        /// <summary>
        /// 中介详情信息（24/7/3添加） 和 channel绑定
        /// </summary>
         public string BrokerDetailInfo { get; set; }


        public int[] RealTradeIdList { get; set; }


        /// <summary>
        /// 交割速度（24/7/16添加）
        /// </summary>
        public string DeliverySpeed { get; set; }

        /// <summary>
        /// 强平ID（24/7/24添加）
        /// </summary>
        public string QiangPingId { get; set; }

        public string ChannelID { get; set; }

        public override string ToString()
        {
            return $"UserTrade [id={Id}, 目标={Target}, ChatID={ChatID}, Broker={Broker}, BrokerID={BrokerID}, " +
                   $"ReceiverId={ReceiverId}, 券码={TsCode}, UserTradeID={UserTradeID}, UserID={UserID}, UserName={UserName}, " +
                   $"状态={StatusText}, Volume={Volume}, 价格={Price}, DeliveryDate={DeliveryDate}, " +
                   $"交易类型={DealType}, Time={Time}, 命令={Command}, OrderType={OrderType}, Guid={Guid}, " +
                   $" OnHoldVolume={OnHoldVolume}, CounterParty={CounterParty}]"+
                   $"频道ID={ChannelID}";
        }

        #region 钟老师添加？
        private ObservableCollection<UserTrade> _children;

        public ObservableCollection<UserTrade> Children
        {
            get { return _children; }
            set
            {
                if (_children != value)
                {
                    _children = value;
                    OnPropertyChanged(nameof(Children)); // Notify that Children property has changed
                }
            }
        }

        /// <summary>
        /// 券类型
        /// </summary>
        private string tsCodeType;

        public string TsCodeType
        {
            get { return tsCodeType; }
            set { tsCodeType = value; }
        }


        /// <summary>
        /// 券年限
        /// </summary>
        private string tsCodeTerm;

        public string TsCodeTerm
        {
            get { return tsCodeTerm; }
            set { tsCodeTerm = value; }
        }

        /// <summary>
        /// 券PVBP
        /// </summary>
        private decimal pvbp;

        public decimal PVBP
        {
            get { return pvbp; }
            set { pvbp = value; }
        }

        /// <summary>
        /// 是否选中状态（提交审核）
        /// </summary>
        private bool isSelected = false;

        public bool IsSelected
        {
            get { return isSelected; }
            set { isSelected = value; OnPropertyChanged(); }
        }
        /// <summary>
        /// 是否能撤单（和按钮有关）
        /// </summary>
        private bool isCancelable=false;

        public bool IsCancelable
        {
            get { return isCancelable; }
            set { isCancelable = value; OnPropertyChanged(); }
        }


        /// <summary>
        /// 是否能改价（和按钮有关）
        /// </summary>
        private bool isChangepriceable=true;

        public bool IsChangepriceable
        {
            get { return isChangepriceable; }
            set { isChangepriceable = value; OnPropertyChanged(); }
        }

        public string? RealVolume { get; set; }
        public DateTime? UpdateTime { get; set; }
        public DateTime? TradeTime { get; set; }
        public DateTime? TradeTime2 { get; set; }
        public string? TradeNum { get; set; }
        public string DeliverySpeedFormat { get; set; }
        #endregion

    }
}
